/*******************************************************************************
 * Copyright (c) 2001, 2002 Boris Pruessmann and others.
 * All rights reserved.   This program and the accompanying materials
 * are made available under the terms of the Common Public License v0.5
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/cpl-v05.html
 * 
 * Contributors:
 *    Boris Pruessmann - Initial implementation.
 ******************************************************************************/
package net.sourceforge.perforce.ui.prefs;

import net.sourceforge.perforce.ui.IPerforceUIConstants;
import net.sourceforge.perforce.ui.PerforceUIPlugin;
import net.sourceforge.perforce.ui.internal.Policy;

import org.eclipse.jface.preference.BooleanFieldEditor;
import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;

/**
  * @version $Revision: 1.3 $
  * @author  <a href="mailto:bpruessmann@users.sourceforge.net">Boris Pruessmann</a>
  */
public class P4PreferencePage 
	extends FieldEditorPreferencePage 
	implements IWorkbenchPreferencePage 
{
	// ------------------------------------------------------------------------- Public Constructors
	
	/** Constructor for P4PreferencePage. */
	public P4PreferencePage() 
	{
		super(FieldEditorPreferencePage.GRID);
		setPreferenceStore(PerforceUIPlugin.getPlugin().getPreferenceStore());		
	}

	// ------------------------------------------------------------------------------ Public Methods

	/** @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench) */
	public void init(IWorkbench workbench) 
	{
	}

	// --------------------------------------------------------------------------- Protected Methods

	/** @see FieldEditorPreferencePage#createFieldEditors() */
	protected void createFieldEditors() 
	{
		Label label = new Label(getFieldEditorParent(), SWT.NULL);
		label.setText("General Perforce settings:");
		label.setFont(JFaceResources.getDialogFont());
		
		BooleanFieldEditor deleteAffectesChangelist = new BooleanFieldEditor(
			PerforceUIPlugin.DELETE_AFFECTS_CHANGELIST,
			Policy.bind("PerforcePreferencePage.deleteAffectsChangelist"),             //$NON-NLS-1$
			getFieldEditorParent());
		addField(deleteAffectesChangelist);
		
		BooleanFieldEditor showTasksOnAdd = new BooleanFieldEditor(
			IPerforceUIConstants.PREF_SHOW_TASKS_ON_ADD,
			"Show added markers",
			getFieldEditorParent());
		addField(showTasksOnAdd);
		
		BooleanFieldEditor dontPromptOnOpen = new BooleanFieldEditor(
			IPerforceUIConstants.PREF_DONT_PROMPT_AUTOMATIC_OPEN,
			"Automatically open files on edit",
			getFieldEditorParent());
		addField(dontPromptOnOpen);
		
		BooleanFieldEditor warnOnOtherOpen = new BooleanFieldEditor(
			IPerforceUIConstants.PREF_WARN_ON_OTHER_OPEN,
			"Warn when opening files that are also opened by others.",
			getFieldEditorParent());
		addField(warnOnOtherOpen);
		
		BooleanFieldEditor checkChangelists = new BooleanFieldEditor(
			IPerforceUIConstants.PREF_CHECK_CHANGELIST_FOR_WARNINGS_AND_ERROR,
			"Warn when submitting changelist that has warnings/errors",
			getFieldEditorParent());
		addField(checkChangelists);
	}
}
